package com.ly.sy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ly.sy.entity.Comment;
import com.ly.sy.entity.Course;
import com.ly.sy.entity.Syuser;
import com.ly.sy.mapper.CommentMapper;
import com.ly.sy.mapper.SyuserMapper;
import com.ly.sy.service.CommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ly.sy.service.SyuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liangyu
 * @since 2020-11-11
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {

    @Autowired
    private SyuserService syuserService;
    @Override
    public List<Comment> findCidAndFathernull(Integer courseid, Integer father) {
        QueryWrapper<Comment> queryWrapper=new QueryWrapper<>();
        if(courseid==null){
            queryWrapper.eq("father",father);
        }else {
            queryWrapper.eq("father",father);
            queryWrapper.eq("course_id",courseid);
        }
        List<Comment> CommentFormSql= list(queryWrapper);
        return CommentFormSql;
    }

    @Override
    public Syuser findUserByid(Integer userid) {
        System.out.println("userid:"+userid);

        QueryWrapper<Syuser> queryWrapper=new QueryWrapper<>();

        queryWrapper.eq("user_id",userid);

        Syuser CommentFormSql= syuserService.getOne(queryWrapper);
        return CommentFormSql;
    }

    @Override
    public List<Comment> commentlikeLise(String searchstr) {
        QueryWrapper<Comment> queryWrapper=new QueryWrapper<>();

        queryWrapper.like("comment_p",searchstr);

        List<Comment> CommentFormSql= list(queryWrapper);
        return CommentFormSql;
    }
}
